class Car:
    def __init__(self, io_strategy, num):
        self.inventory_number = num
        self.year = None
        self.model = None
        self.type = "car"
        self.io_strategy = io_strategy
        self.set_model()
        self.set_year()

    def set_inventory_number(self, num):
        self.inventory_number = num

    def set_model(self):
        self.model = self.io_strategy.input("model")

    def set_year(self):
        self.year = self.io_strategy.input("year")

    def show_all(self):
        try:
            self.io_strategy.output(self)
        except Exception as e:
            print(e.args[0])

    def __str__(self):
        return f"\n№: {self.inventory_number}\nТип: {self.type}\nГод выпуска:{self.year}\nМодель:{self.model}"

    def __keys__(self):
        return ["inventory_number", "year", "type", "model"]

    def __getitem__(self, key):
        # have obj["a"] -> obj.a
        return self.__getattribute__(key)

    def asdict(self):
        return {
            "inventory_number": self.inventory_number,
            "year": self.year,
            "type": self.type,
            "model": self.model,
        }

    def edit(self):
        self.set_model()
        self.set_year()

    def to_json(self):
        return {
            "id": str(self.inventory_number),
            "year": self.year,
            "model": self.model,
            "type": self.type,
        }
